/*
 *@Description: 第一次采集主入口
 *@Author: panlua
 *@Date: 2019-07-01 15:37:21
*/

const mongoose = require('mongoose')
const db = require('./db/config')
const moment = require('moment')
// 导入定时库
const schedule = require('node-schedule')

// 制定定时采集规则
const Rule = new schedule.RecurrenceRule()
Rule.hour = [2]

// 导入工具库
require('./utils/index');
// 导入采集小说信息方法
const gatBook = require('./methods/index');

(async () => {
  await mongoose.connect(db.dbUrl, {
    useNewUrlParser: true
  }, err => {
    if (err) return LOG.error('数据库连接失败：' + err)
    LOG.success('数据库连接成功')
  })
  await gatBook()
  schedule.scheduleJob(Rule, async() => {
    LOG.success(`自动采集任务启动成功,${moment().format('YYYY-MM-DD hh:mm:ss')}`);
    await gatBook()
  })
})()